]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
panel: programmatic anim. control of AnimatedIcon
authorStéphane Démurget <stephane.demurget@free.fr>
Sun, 4 Nov 2012 18:47:11 +0000 (19:47 +0100)
committerStéphane Démurget <stephane.demurget@free.fr>
Mon, 5 Nov 2012 14:05:14 +0000 (15:05 +0100)
The AnimatedIcon does not have an API for controlling the animation but
relies on the :visible property changes to start and stop a timeout used
to update the frame.

This has the inconvenient of having a side effect when visible is set to
true multiple times, and is not really the API expected from such
component.

Switch to a start/stop API instead. Also, update to the first frame at
startup while we are at it, since this is the expected behavior.

https://bugzilla.gnome.org/show_bug.cgi?id=687583

js/ui/panel.js

index 9f36963465d28e8842b8f205f63d2e30caef3e9e..2c3fc89a659a722bf9fbdd5238b4e7fdee5b2709 100644 (file)
@@ -82,28 +82,27 @@ const AnimatedIcon = new Lang.Class({
     _init: function(name, size) {
         this.actor = new St.Bin({ visible: false });
         this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
-        this.actor.connect('notify::visible', Lang.bind(this, this._onVisibleNotify));
 
         this._timeoutId = 0;
         this._frame = 0;
         this._animations = St.TextureCache.get_default().load_sliced_image (global.datadir + '/theme/' + name, size, size);
         this.actor.set_child(this._animations);
+
+        this._update();
+    },
+
+    start: function() {
+        if (this._timeoutId == 0)
+            this._timeoutId = Mainloop.timeout_add(ANIMATED_ICON_UPDATE_TIMEOUT, Lang.bind(this, this._update));
     },
 
-    _disconnectTimeout: function() {
+    stop: function() {
         if (this._timeoutId > 0) {
             Mainloop.source_remove(this._timeoutId);
             this._timeoutId = 0;
         }
     },
 
-    _onVisibleNotify: function() {
-        if (this.actor.visible)
-            this._timeoutId = Mainloop.timeout_add(ANIMATED_ICON_UPDATE_TIMEOUT, Lang.bind(this, this._update));
-        else
-            this._disconnectTimeout();
-    },
-
     _showFrame: function(frame) {
         let oldFrameActor = this._animations.get_child_at_index(this._frame);
         if (oldFrameActor)
@@ -122,7 +121,7 @@ const AnimatedIcon = new Lang.Class({
     },
 
     _onDestroy: function() {
-        this._disconnectTimeout();
+        this.stop();
     }
 });
 
@@ -367,6 +366,7 @@ const AppMenuButton = new Lang.Class({
                            transition: "easeOutQuad",
                            onCompleteScope: this,
                            onComplete: function() {
+                               this._spinner.stop();
                                this._spinner.actor.opacity = 255;
                                this._spinner.actor.hide();
                            }
@@ -376,6 +376,7 @@ const AppMenuButton = new Lang.Class({
     startAnimation: function() {
         this._stop = false;
         this.actor.reactive = false;
+        this._spinner.start();
         this._spinner.actor.show();
     },